<template>
  <base-breadcrumb>

    <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
      <title-name title="月计划"></title-name>
      <div class="table-operator">
        <a-button type="primary" icon="plus" @click="saveInfo()">保存信息</a-button>
        <a-button type="primary" :disabled="level != 4 || selectedRow.isMonthWeekCreated == false" @click="deleteNode()">删除节点</a-button>
        <!--<a-button type="primary" @click="handleAdd">新增节点</a-button>-->
        <a-button type="primary" :disabled="level != 4" @click="handleAddSame">新增同级节点</a-button>
        <!--<a-button type="primary" @click="handleAddDown">新增下级节点</a-button>-->
        <a-button type=""  @click="moveOneDay">前移一天</a-button>
        <!--<a-button type=""  @click="">全部恢复</a-button>-->
        <!--<a-button type=""  @click="">回撤</a-button>-->
      </div>

      <div class="pub-table-select-count">
        <a-icon type="info-circle" theme="twoTone"/>
        <span style="margin-right: 12px">
           项目名称：<span class="totalNum">{{projectName}}</span> |
           当前进行月计划：<span class="totalNum">{{ deltailsTotal.planTime}} </span> |
           本月需进行节点总数：<span class="totalNum">{{ deltailsTotal.conductTotal}} </span> 个 |
           本月计划开始节点数：<span class="totalNum">{{ deltailsTotal.startTotal}} </span> 个 |
           本月计划结束节点数：<span class="totalNum">{{ deltailsTotal.endTotal}} </span> 个 |
           延期到本月节点数：<span class="totalNum">{{ deltailsTotal.delayTotal}} </span> 个
        </span>
      </div>

      <a-table row-key="id" :scroll="{ x: 2400 }"
               :columns="columns"
               :defaultExpandAllRows="true"
               :pagination="false"
               :expandIconColumnIndex="2"
               :data-source="datas"
               :rowClassName="rowClassNames"
               :customRow="selectRow"
      >
      <!--<a-table :scroll="{ x: 2400}"  row-key="id" :defaultExpandAllRows="true" :columns="columns"  :rowClassName="rowClassNames"  :expandIconColumnIndex="2"  :data-source="datas"  :customRow="selectRow" >-->

        <template slot="num" slot-scope="text, record, index">
          <span v-if="record.promptLights == 1&&record.promptLights!=null "> <img src="../../../assets/icons/yellowLight.png" width="20" hight="20"/></span>
          <span v-if="record.promptLights == 2&&record.promptLights!=null"> <img src="../../../assets/icons/redLight.png" width="20" hight="20"/></span>
          <span v-if="record.statusLights == 1&&record.statusLights!=null"> <div style="background: rgba(224, 244, 223, 1);width: 40px;height: 20px"></div> </span>
          <span v-if="record.statusLights == 2&&record.statusLights!=null"> <div style="background: rgba(251, 230, 232, 1);width: 40px;height: 20px"></div> </span>
          <span v-if="record.statusLights == 3&&record.statusLights!=null"> <div style="background: rgba(240, 153, 164, 1);width: 40px;height: 20px"></div> </span>
        </template>

        <template slot="name" slot-scope="text, record">
          <span v-if="record.level != 4 && record.isMonthWeekCreated == false "><ellipsis :length="20" tooltip>{{record.name}}</ellipsis></span>
          <BaseInput  type="textarea"  style="height:45px;width:300px"   v-if="record.level != 4 && record.isMonthWeekCreated == true && record.statusCode !=3 " @blur="onCellChangeName" :value="record.name"  :text="text" placeholder='请输入'/>
        </template>


        <template slot="businessMatters" slot-scope="text, record">
          <span v-if="record.level==4 && record.isMonthWeekCreated == false ">
           <ellipsis :length="40" tooltip>{{record.businessMatters}}</ellipsis>
          </span>
          <BaseTextarea   v-if="record.level==4 && record.isMonthWeekCreated == true && record.statusCode !=3"  @blur="onCellChangeBusiness" v-model="record.businessMatters"  :text="text" placeholder='请输入'/>
        </template>

        <template slot="controLevel" slot-scope="text, record">
          <span v-if="record.level==4 && record.isMonthWeekCreated == false ">{{record.controlLevelName}}</span>
          <cell @changes="onCellChangeControLevel" style="width: 300px;" v-if="record.level==4 && record.isMonthWeekCreated == true && record.statusCode !=3" formType="select"  :value="record.controlLevelId"  :text="record.controlLevelId" >
            <a-select-option  v-for="item in nodeControls" :disabled="item.controlLevelId == 1 || item.controlLevelId== 2" :key="item.controlLevelId"  :value="item.controlLevelId" >{{item.controlLevelName}}</a-select-option>
          </cell>
        </template>

        <!--<template slot="duration" slot-scope="text, record">-->
          <!--<span v-if="record.level==4 && record.isMonthWeekCreated == false ">{{record.duration}}</span>-->
          <!--<BaseInput v-if="record.level==4 && record.isMonthWeekCreated == true " @blur="onCellChangeDuration" :value="record.duration"  :text="text" placeholder='请输入'/>-->
        <!--</template>-->

        <template slot="startTime" slot-scope="text, record">
          <a-date-picker :allowClear="false" v-if="record.level==4 && record.statusCode !=3" @change="handleChangeStart"  placeholder='请输入日期' :value="record.startTime" :text="text"/>
          <span v-else>{{record.startTime}}</span>
        </template>

        <template slot="endTime" slot-scope="text, record">
          <a-date-picker :allowClear="false" v-if="record.level==4 && record.statusCode !=3"   @change="handleChangeEnd"   placeholder='请输入日期' :value="record.endTime" :text="text"/>
          <span v-else>{{record.endTime}}</span>
        </template>

        <template slot="completeStandard" slot-scope="text, record">
            <span v-if="record.level==4 && record.isMonthWeekCreated == false ">
              <ellipsis :length="40" tooltip>{{record.completeStandard}}</ellipsis>
            </span>
          <BaseTextarea  v-if="record.level==4 && record.isMonthWeekCreated == true && record.statusCode !=3"   @blur="handleChangeStandard" v-model="record.completeStandard" :text="text" placeholder='请输入'/>
        </template>

        <template slot="verifyDoc" slot-scope="text, record">
          <span v-if="record.level==4 && record.isMonthWeekCreated == false ">
            <ellipsis :length="40" tooltip>{{record.verifyDoc}}</ellipsis>
          </span>
          <BaseTextarea  v-if="record.level==4 && record.isMonthWeekCreated == true && record.statusCode !=3 "   @blur="handleChangeValidations" v-model="record.verifyDoc" :text="text" placeholder='请输入'/>
        </template>

        <template slot="firstResponsible" slot-scope="text, record">
          <a-tooltip placement="topLeft" @visibleChange="getDatas(record.firstResId)"  :title="infos">
            <span v-if="record.isMonthWeekCreated == false">{{record.firstResponsible}}</span>
            <span v-if="record.level==4 && record.isMonthWeekCreated == true  && record.firstResponsible != null">{{record.firstResponsible}}</span>
            <a  v-if="record.level==4 && record.isMonthWeekCreated == true  && record.firstResponsible != null && record.statusCode !=3"    @click="handleBind(record)"> (重新选择)</a>
            <a  v-if="record.level==4 && record.isMonthWeekCreated == true && record.firstResponsible==null && record.statusCode !=3"   @click="handleBind(record)">选择第一责任人</a>
          </a-tooltip>
        </template>

        <template slot="responsible" slot-scope="text, record">
          <a-tooltip placement="topLeft" @visibleChange="getPosts(record.responsibleId)"  :title="pensonalPosts">
              <span v-if="record.isMonthWeekCreated == false">{{record.responsible}}</span>
              <a-select @focus="getOrganizePeopleList"  :getPopupContainer="getPopupContainer"   v-if="record.level==4 && record.isMonthWeekCreated == true && record.statusCode !=3"    placeholder="请选择" v-model="record.responsible" style="width:100px" @change="handleChangeEngineer">
                <a-spin v-if="loading" slot="notFoundContent" size="small" />
                <a-select-option v-for="item in responsLists" :key="item.employeeId" :value="item.employeeId">{{item.employeeName}}</a-select-option>
              </a-select>
          </a-tooltip>
        </template>

      </a-table>

      <add-level
              ref="createModal"
              :visible="visible"
              :model="mdl"
              @cancel="handleCancel"
              @ok="handleOk"/>
    <modal  :id="currentId"  :orgQuery="orgQuery" :screening="screening"    :visible="bindOrgVisible"  @handleCancelFirstRes="handleCancelFirstRes" @handleOk="handlefirstRes"></modal>
    </a-card>

    <div class="page-btn-right-top">
    <!-- <div style="float: right; margin-top: 20px; margin-bottom: 20px"> -->
      <a-button type="primary" style="margin-right: 20px" @click="submit" :loading="loading">提交</a-button>
      <a-button type="primary" @click="goBack">关闭</a-button>
    </div>
  </base-breadcrumb>
</template>

<script>
  import { Ellipsis } from '@/components'
  import FooterToolBar from '@/components/FooterToolbar'
  import addLevel from './addLevel'
  import { addSameNode, addDownNode } from '@/api/template'
  import { getMonthPlanDetails,editMonthPlan,addMonthPlanSameNode,addMonthPlanDownNode,moveMonthPlanOneDay,deleteMonthNode,monthPlanAudit } from '@/api/construction/monthPlan'
  import { getConstructionsList } from '@/api/construction'
  import { getProjectJobsList } from '@/api/project/projectsJobs'
  import modal from '@/components/SelectJobs' // 第一责任人
  import { getOrganizePeopleList,getOrgUserPosts } from '@/api/commons'
  import { getStaffAll } from '@/api/subassembly/TreeSelectOrganization'
  import { employeesDetail } from '@/api/material/assets/parameter'
  import Vue from 'vue'
  import { getProjects } from '@/api/construction/planInput'


  export default {
    name: 'StandardList',
    components: {
      addLevel,
      Ellipsis,
      FooterToolBar,
      modal
    },
    props: {
      text: String
    },
    data() {
      return {
        infos:[],
        pensonalPosts:[],

        nodeControls:[], // 管控级别

        levelNodeControl:[], // 第三级节点
        deltailsTotal:{},
        posts:[ ],
        responsLists:[],
        columns:'',
        visible: false,
        currentId:'',
        mdl: null,
        selectedRowParent:null,
        editingKey:'',
        datas:[],
        bindOrgVisible:false,
        projectName:'',
        projectId:'',
        selectId:'',
        level:0,
        loading:false,
        selectedRowKeys:[],
        selectedRow:{},
        startTime:'',   // 开始时间
        endTime:'' ,     // 结束时间
        editData:{},

        orgQuery: { },
        screening: true,
        id:'',

      }
    },
    created() {

      const userInfo = Vue.getAcloudProvider().getUserInfo()
      this.currentId = userInfo.id
      this.columns = this.getColumns()
      this.id = this.$route.query.id
      this.getConstructionsList()
      this.getMonthPlanDetails()
      this.getProjectJobsList()  // 项目岗位\
    },
    computed: {

    },
    mounted(){
      this.$nextTick(function() {
           document.addEventListener("click",this.selectRow);
      });
    },
    methods: {
      // 查询第一责任人 姓名 电话 岗位
      getDatas(val){
        let that = this

        that.infos = []

        // 根据岗位id 查询人员的电话 姓名
        if(val !=''&& val!=null  ){
          getStaffAll({postId:val}).then(res=>{
            if(res.data && res.data.length > 0){
              let arr = []
              res.data.forEach(function(obj,i) {
                let item = {}
                item.name = obj.name
                item.phone = obj.phone

                arr.push(item)
              })

              var arrys = arr.map(function(objs,index){
                return objs.name + ',' + objs.phone;
              }).join(",");
              that.infos = arrys

            }
          })
        }




      },

      // 查询直接责任人 电话 岗位
      getPosts(val){
        let that = this

        that.pensonalPosts = []

        // 根据岗位id 查询人员的电话 姓名
        if(val !='' && val != null){
          getOrgUserPosts({employeeId:val}).then(ress=>{
            that.pensonalPosts = [ress.data]

          })
        }

      },
      deleteNode(){
        let _this = this

        _this.$confirm({
          title: '删除节点',
          content: '确定删除新增节点吗？',
          onOk() {
            deleteMonthNode({id:_this.selectedRow.id}).then(res=>{
              if(res.code == 200 || res.data.code == 200){
                _this.getMonthPlanDetails()
              }
            })
          },
          onCancel() {},
        });
      },
      handleBind(){
        this.bindOrgVisible = true
      },
      handleCancelFirstRes(){
        this.bindOrgVisible = false
      },
      getProjects(id) {
          const params = {
              projectIds: [id],
          }
          getProjects(params).then((res) => {
            console.log( res.data )
              this.orgQuery.ids = res.data[0].orgId
          })
      },
      getPopupContainer(triggerNode){
        return  triggerNode.parentNode
      },
      // 直接责任人查询
      getOrganizePeopleList(){
        this.loading=true
        getOrganizePeopleList({id:this.projectId}).then(res=>{
          this.responsLists = res.data
          this.loading=false
        })
      },
      getConstructionsList(){
        let that = this;
        getConstructionsList({pageNo:1,pageSize:50}).then(res=>{
          if(res.code == 200){
            let arr = res.data
            let arrys = []
            arr.forEach((item,i)=>{
              let obj = {}
              obj.controlLevelId = parseInt(item.controlLevelId)
              obj.controlLevelName =  item.controlLevelName
              arrys.push(obj)
            })
            that.nodeControls = arrys
          }
        })
      },
      selectRow(record){
        return {
          on: {
            click: () => {
              this.selectId = record.id
              this.level = record.level   // 当前选中是第几级
              this.selectedRow = record   // 当前行数据
              this.editData = record // 同步一下数据
              console.log("选中当前行数据：", this.selectedRow)
              this.columns = this.getColumns()  // 复制当前行属性数据
              this.rowClassNames(record)
            }
          }
        }
      },

      getProjectJobsList(){
        getProjectJobsList().then(res=>{
          this.posts = res.data
        })
      },
      getMonthPlanDetails(){
        let that = this;
        const findSelectedRow = (children)=>{
          children.some((c)=>{
            if(c.id===that.selectedRow.id){
              that.selectedRow = c;
              return true
            }
            if(c.children&&c.children.length>0){
               return findSelectedRow(c.children)
            }
            return false
          })
        }
        getMonthPlanDetails(that.$route.query.id).then(res=>{
          that.projectName = res.data.projectName
          that.projectId = res.data.projectId
          that.getProjects(res.data.projectId)
          if(res.code == 200){
            that.datas = res.data.list
            that.deltailsTotal = res.data
            if(that.selectedRow.id){
              findSelectedRow(that.datas)
            }

          }


        })
      },
      getColumns(){
        let rowIndex = 1
        return [
          {
            title: '',
            dataIndex: 'num',
            width: 60,
            scopedSlots: { customRender: 'num' },
          },
          {
            title: '编号',
            width: 60,
            // customRender:(text,record,index)=>`${index+1}`
            dataIndex: 'sortNum',
          },
          {
            title: '阶段/类别',
            dataIndex: 'name',
            width:370,
            scopedSlots: { customRender: 'name' }
          },
          {
            title: '业务事项',
            dataIndex: 'businessMatters',
            className: 'column-date',
            width:240,
            scopedSlots: { customRender: 'businessMatters' }
          },
          {
            title: '管控级别',
            dataIndex: 'controLevel',
            className: 'column-date',
            width:180,
            scopedSlots: { customRender: 'controLevel' }
          },
          {
            title: '周期（天） ',
            dataIndex: 'duration',
            className: 'column-date',
            width:200,
            scopedSlots: { customRender: 'duration' }
          },
          {
            title: '计划开始时间',
            dataIndex: 'startTime',
            className: 'column-date',
            width:150,
            scopedSlots: { customRender: 'startTime' }
          },
          {
            title: '计划完成时间',
            dataIndex: 'endTime',
            className: 'column-date',
            width:150,
            scopedSlots: { customRender: 'endTime' }
          },
          {
            title: '实际完成时间',
            dataIndex: 'completeTime',
            className: 'column-date',
            width:150,
          },
          {
            title: '完成标准',
            dataIndex: 'completeStandard',
            width:300,
            className: 'column-date',
            scopedSlots: { customRender: 'completeStandard' }
          },
          {
            title: '验证资料',
            dataIndex: 'verifyDoc',
            className: 'column-date',
            width:300,
            scopedSlots: { customRender: 'verifyDoc' }
          },
          {
            title: '第一责任人',
            dataIndex: 'firstResponsible',
            className: 'column-date',
            width:300,
            scopedSlots: { customRender: 'firstResponsible' }
          },
          {
            title: '直接责任人',
            dataIndex: 'responsible',
            className: 'column-date',
            width:300,
            scopedSlots: { customRender: 'responsible' }
          },
          {
            title: '节点状态',
            className: 'column-date',
            width:150,
            dataIndex: 'statusName',
          },
        ]
      },

      onCellChangeName(e){
        this.selectedRow.name = e.target.value
        this.editData.id = this.selectedRow.id
        this.editData.name = e.target.value
        editMonthPlan(this.editData).then(res=>{
          if(res.code == 200){
            this.getMonthPlanDetails()
          }
        })
      },
      handlefirstRes(value){
        this.bindOrgVisible = false
        let data={
          id:this.selectedRow.id,
          firstResId:value.jobsSelectedId,
          firstResponsible:value.jobsSelectedName,
        }
        editMonthPlan(data).then((res)=>{
          if(res){
            this.getMonthPlanDetails()
          }
        })
      },
      onCellChangeControLevel(e){
        this.selectedRow.controLevel = e
        this.editData.id = this.selectedRow.id
        this.editData.controLevel = e
        editMonthPlan(this.editData).then(res=>{
          if(res.code == 200){
            this.getMonthPlanDetails()
          }
        })
      },
      /**
       * 修改业务事项
       */
      onCellChangeBusiness(e){
        this.selectedRow.businessMatters = e.target.value
        this.editData.id = this.selectedRow.id
        this.editData.businessMatters = e.target.value
        editMonthPlan(this.editData).then(res=>{
          if(res.code == 200){
            this.getMonthPlanDetails()
          }
        })
      },
      onCellChangeFocus(e){
        console.log("hfkjsahfjd:",e.target.value)
        this.selectedRow.businessMatters = e.target.value
      },
      onCellChangeDuration(e){
        this.selectedRow.duration = e.target.value
        this.editData.id = this.selectedRow.id
        this.editData.duration = e.target.value
        editMonthPlan(this.editData).then(res=>{
          if(res.code == 200){
            this.getMonthPlanDetails()
          }
        })
      },
      handleChangeStandard(e){
        this.editData.id = this.selectedRow.id
        this.editData.completeStandard = e.target.value
        editMonthPlan(this.editData).then(res=>{
          if(res.code == 200){
              this.getMonthPlanDetails()
          }
        })
      },

      handleChangeValidations(e){
        this.editData.id = this.selectedRow.id
        this.editData.verifyDoc = e.target.value
        editMonthPlan(this.editData).then(res=>{
          if(res.code == 200){
            this.getMonthPlanDetails()
          }
        })
      },

      handleChangeRes(val){
        this.selectedRow.firstResponsible = val
        this.editData.id = this.selectedRow.id
        this.editData.firstResponsible = val
        editMonthPlan(this.editData).then(res=>{
          if(res.code == 200){
            this.getMonthPlanDetails()
          }
        })
      },

      handleChangeEngineer(value){
        this.editData.id = this.selectedRow.id
        this.editData.responsibleId = value
        let arr=this.responsLists.filter(item=>item.employeeId==value)
        this.editData.responsible = arr[0].employeeName
        editMonthPlan(this.editData).then(res=>{
          if(res.code == 200){
            this.getMonthPlanDetails()
          }
        })
      },


      handleChangeStart(val){
        if(val != null){
          this.startTime = val.format('YYYY-MM-DD')
        }

        if( this.selectedRow.endTime !="" && this.selectedRow.endTime != null ){
          this.endTime = this.selectedRow.endTime
          var startTime = new Date(this.startTime)
          var endTime = new Date(this.endTime)
          if( startTime > endTime ){
            this.$message.error("计划开始时间不能大于计划结束时间！")
            return;
          }else{
            this.editData.id = this.selectedRow.id
            this.editData.startTime = val.format('YYYY-MM-DD')
            editMonthPlan(this.editData).then(res=>{
              if(res.code == 200){
                this.getMonthPlanDetails()
              }
            })
          }
        }else{
          this.editData.id = this.selectedRow.id
          this.editData.startTime = val.format('YYYY-MM-DD')
          if(this.selectedRow.endTime == null){
            this.editData.endTime = null
          }

          editMonthPlan(this.editData).then(res=>{
            if(res.code == 200){
              this.getMonthPlanDetails()
            }
          })
        }



      },
      handleChangeEnd(val){
        this.endTime = val.format('YYYY-MM-DD')


        if(this.endTime == ""){
          this.endTime = this.selectedRow.endTime
        }

        // 周期（天）
        var startTime = new Date(this.selectedRow.startTime)
        var endTime = new Date(this.endTime) // 修改时间
        let oldEndDate = new Date(this.selectedRow.oldEndDate)  // 生成时间

        if(this.selectedRow.isMonthWeekCreated == false){
          if(endTime > oldEndDate){
            this.$message.error("计划完成时间最大能调整到生成时间: "+ this.selectedRow.oldEndDate)
            val = this.selectedRow.endTime
            return;
          }
        }

        if(this.selectedRow.endTime != null && this.selectedRow.isMonthWeekCreated == false){
          var time1 = new Date(this.selectedRow.endTime) // 改过之前时间
          if(endTime > time1 && endTime > oldEndDate){
            this.$message.error("计划完成时间只能往前调整并且小于等于生成时间: " + this.selectedRow.oldEndDate)
            val = this.selectedRow.endTime
            return;
          }
        }

        if(endTime < startTime){
          this.$message.error("计划完成时间不能小于计划开始时间！")
          val = this.selectedRow.endTime
          return;
        }else{
          let iDays = parseInt(Math.abs(endTime.getTime()- startTime.getTime()) /1000/60/60/24);
          this.selectedRow.duration = iDays
        }

        this.editData.id = this.selectedRow.id
        this.editData.endTime = val.format('YYYY-MM-DD')
        if(this.selectedRow.startTime == null){
          this.editData.startTime = null
        }
        editMonthPlan(this.editData).then(res=>{
          if(res.code == 200){
            this.getMonthPlanDetails()
          }
        })

      },


      getParentNode(items){
        items.some(d=>{
          if( d.id ===this.selectedRow.parentId){
            this.selectedRowParent = d;
            return true;
          }
          if(d.children&&d.children.length>0){
            this.getParentNode(d.children)
          }
        })
      },
      handleOk() {
        const form = this.$refs.createModal.form
        form.validateFields((errors, values) => {
          if (!errors) {

            this.editData.planId  = this.$route.query.id
            this.editData.level  = this.selectedRow.level
            this.editData.id  = this.selectedRow.id

            if(values.level === "0"){   // 0是同级  1是下级

              this.visible = false

              addMonthPlanSameNode(this.editData).then(res=>{
                  if(res.code == 200){
                    this.getMonthPlanDetails()
                  }
              })



            }else if(values.level === "1" && this.level !=4) {
              this.visible = false

              addMonthPlanDownNode(this.editData).then(res=>{
                if(res.code == 200){
                  this.getMonthPlanDetails()
                }
              })



            }else{
              this.$message.error("四级节点不能新增下级！")

            }
          }
        })
      },

      handleCancel() {
        this.visible = false
        const form = this.$refs.createModal.form
        form.resetFields() // 清理表单数据（可不做）
      },



      rowClassNames(record){
        if( this.selectId == record.id ){
          return 'clickRowStyle'
        }
      },

      saveInfo(){
        if(this.level == 0 || this.level != 4){
          this.$message.error("请先选中节点！")
          return;
        }
        this.$message.success("保存成功!")
        this.$multiTab.close(this.$route.fullpath)

      },
      // 提交审核
      submit(){
        let that = this
        if(that.loading){
          return
        }
        that.loading = true
        monthPlanAudit({id:that.id}).then(res=>{
          that.loading = false
          if (res.data.code == 200) {
            that.$message.success("提交成功!")
            that.$multiTab.close(that.$route.fullpath)
          }
        }).catch(() => {
          that.loading = false
        })
      },
      goBack(){
        this.$multiTab.close(this.$route.fullpath)
      },


      moveOneDay(){
        let that = this;

        if( that.level == ''){
          that.$message.error("请先选中节点！")
        }else{
          // document.getElementsByClassName("clickRowStyle").click();


          // let arr = []
          // arr.push(this.selectedRow)
          // this.onSelectChange(this.selectedRowKeys,arr)

          if(that.selectedRow.startTime == null || that.selectedRow.endTime == null){
            that.$message.error("请先选择计划开始时间和计划结束时间")
            return;
          }

          that.editData.id = that.selectedRow.id
          that.editData.startTime = that.selectedRow.startTime
          that.editData.endTime = that.selectedRow.endTime

          moveMonthPlanOneDay(that.editData).then(res=>{
            if(res.code == 200){
              that.getMonthPlanDetails()
              // this.onSelectChange(this.selectedRowKeys,arr)
            }
          })
        }
      },
      handleAdd(){
        if( this.level == ''){
          this.$message.error("请先选中节点！")
        }else{
          this.visible = true
        }
      },

      // 新增同级节点
      handleAddSame(){

        let _this = this

        if( _this.level == ''){
          _this.$message.error("请先选中节点！")
          return
        }
        if( _this.level != 4){
          _this.$message.error("工作包不可以新增！")
          return
        }else{
          _this.$confirm({
            title: '新增节点',
            content: '确定新增同级节点吗？',
            onOk() {
              _this.editData.planId  = _this.$route.query.id
              _this.editData.level  = _this.selectedRow.level
              _this.editData.id  = _this.selectedRow.id
              addMonthPlanSameNode(_this.editData).then(res=>{
                if(res.code == 200 || res.data.code ==200){
                  _this.getMonthPlanDetails()
                }
              })
            },
            onCancel() {},
          });
        }
      },
      // 新增下级节点
      handleAddDown(){
        let _this = this
        if( _this.level == ''){
          _this.$message.error("请先选中节点！")
          return
        }else if(_this.level != 3){
          _this.$message.error("只能新增三级工作包！")
          return
        } else if(_this.level == 4){
          _this.$message.error("四级节点不能新增下级！")
          return
        } else{
          _this.$confirm({
            title: '新增节点',
            content: '确定新增下级节点吗？',
            onOk() {
              _this.editData.planId  = _this.$route.query.id
              _this.editData.level  = _this.selectedRow.level
              _this.editData.id  = _this.selectedRow.id
              addMonthPlanDownNode(_this.editData).then(res=>{
                if(res.code == 200){
                  _this.getMonthPlanDetails()
                }
              })

            },
            onCancel() {},
          });
        }
      },
    }
  }
</script>

<style lang="less" scoped>

  /deep/ .ant-table-body  .clickRowStyle{
    background-color: rgb(230, 243, 252);
  }

  /deep/ .column-date.ant-table-row-cell-break-word {
    text-align: center !important;
  }
  .wrapper-row {
    padding-left: 55px;
    font-weight: bold;
    letter-spacing: 1px;
  }

  /deep/ .ant-form-item label {
    font-size: 12px;
  }

  /deep/ .ant-btn {
    border-radius: 5px;
  }

  /deep/ .ant-calendar-picker-input.ant-input {
    width: 100%;
  }

  /deep/ .ant-input {
    /*width: 70%;*/
    border-radius: 5px;
  }

  /deep/ .ant-calendar-picker {
    width: 100%;
    border-radius: 5px;
  }

  /deep/ .ant-card.ant-card-bordered {
    border-radius: 5px;
  }

  .ant-avatar-lg {
    width: 48px;
    height: 48px;
    line-height: 48px;
  }

  .list-content-item {
    color: rgba(0, 0, 0, 0.45);
    display: inline-block;
    vertical-align: middle;
    font-size: 14px;
    margin-left: 40px;
    span {
      line-height: 20px;
    }
    p {
      margin-top: 4px;
      margin-bottom: 0;
      line-height: 22px;
    }
  }

  .title-name {
    border-left: 5px solid #1890ff;
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 20px;
    padding-left: 15px;
    height: 20px;
    line-height: 20px;
  }

  /deep/ .table-page-search-wrapper .ant-form-inline .ant-row .ant-col.ant-col-sm-24.ant-col-md-12 {
    padding-left: 80px;
  }
  /deep/ .ant-table-tbody > tr > td{
  padding:5px !important
}
</style>

